home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok17.lha
/
IFFtoImage
/
Sources
/
ImgDemo.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
4KB
|
137 lines
MODULE ImgDemo;
(* Program to show an Image. *)
FROM Intuition IMPORT CloseWindow, WindowPtr,
IDCMPFlagSet,Image, DrawImage,
IDCMPFlags,ModifyIDCMP,SetWindowTitles,
IntuiMessagePtr, ScreenPtr,
CloseScreen;
FROM Graphics IMPORT RastPortPtr, ViewPortPtr;
FROM Fenster IMPORT BildSchirm, FensterAuf, Info, Farben;
FROM SYSTEM IMPORT ADR,ADDRESS;
FROM FileSystem IMPORT Lookup, ReadBytes, Close, File, Response,
ReadByteBlock, Length;
FROM Exec IMPORT MsgPortPtr, UByte;
FROM Heap IMPORT AllocMem, Deallocate;
FROM Arts IMPORT TermProcedure, Assert, CurrentLevel;
FROM Arguments IMPORT NumArgs, GetArg;
CONST
b = 640; h = 236; (* screensize *)
FensterTitel=" IFFtoImage Demo ";
ScreenTitel =" IFF-DEMO ";
VAR
wPtr :WindowPtr;
sPtr :ScreenPtr;
uPtr :MsgPortPtr;
rPtr :RastPortPtr;
vPtr :ViewPortPtr;
finish :BOOLEAN;
class :IDCMPFlagSet;
code :CARDINAL;
myLevel :INTEGER;
Img :Image; (* Image to display *)
Name :ARRAY[0..79] OF CHAR; (* name of .img-file *)
length :INTEGER;
buffsize,actual :LONGINT;
buffPtr :ADDRESS;
data :File;
PROCEDURE CleanUp;
BEGIN
IF myLevel >= CurrentLevel() THEN
IF wPtr # NIL THEN CloseWindow(wPtr) END;
IF sPtr # NIL THEN CloseScreen(sPtr) END;
IF buffPtr#NIL THEN Deallocate(buffPtr) END;
END;
END CleanUp;
PROCEDURE Initialisierung;
BEGIN
sPtr := BildSchirm(); (* open Screen *)
wPtr := FensterAuf(0,9,b,h,FensterTitel,sPtr);
uPtr := wPtr^.userPort;
rPtr := wPtr^.rPort;
vPtr := ADR(sPtr^.viewPort);
Farben(vPtr);
END Initialisierung;
(* This is a somewhat stupid construction,
but I have to read Bytes and I need LONGINT's *)
TYPE
BLOCK = RECORD
CASE :BOOLEAN OF
| TRUE : l:ARRAY[0..2] OF LONGINT;
| FALSE: b:ARRAY[0..11] OF UByte;
END;
END;
VAR
block :BLOCK;
dlength :LONGINT; (* length of data file *)
BEGIN (* BEGIN of main program *)
Initialisierung;
myLevel := CurrentLevel();
TermProcedure(CleanUp); (* TermProcedure should be called
very early! *)
ModifyIDCMP(wPtr,IDCMPFlagSet{closeWindow});
SetWindowTitles(wPtr,ADR(FensterTitel),ADR(ScreenTitel));
(*------ get name: ------*)
IF NumArgs()#0 THEN
GetArg(1,Name,length);
ELSE
HALT; (* no .img-file, nothing to do *)
END;
(*-------now get data file -------------------------*)
Lookup(data,Name,1024,FALSE); (* FALSE = OldFile *)
Assert(data.res=done,ADR("can't get file!"));
Length(data,dlength); (* need filelength for AllocMem *)
ReadByteBlock(data,block.b);
Assert(data.res=done,ADR("can't get block.b!"));
buffsize := dlength-12;
buffPtr := NIL;
AllocMem(buffPtr,buffsize,TRUE); (* TRUE = ChipMem! *)
Assert(buffPtr#NIL,ADR("couldn't get ChipMem"));
ReadBytes(data,buffPtr,buffsize,actual);
Assert(actual=buffsize,ADR("couldn't get .img-data"));
Close(data);
(* now put Image together *)
WITH Img DO
leftEdge := 10;
topEdge := 10;
width := block.l[0]; (* read as UBytes, used as LONGINTs *)
height := block.l[1];
depth := block.l[2];
imageData := buffPtr;
planePick := 3; (* for planes 0 and 1 to pick *)
planeOnOff := 0;
nextImage := NIL;
END;
DrawImage(rPtr,ADR(Img),10,10);(* do it or die! *)
finish := FALSE; (* just to finish the whole thing! *)
REPEAT
class := Info(uPtr,code);
IF closeWindow IN class THEN finish := TRUE END;
UNTIL finish;
END ImgDemo.mod